<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商家账号添加后台界面</title>
    <link href="../../css/Hui.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .form-item {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10px;
                }

        .form-label {
                    width: 120px;
                    text-align: right;
                    padding-right: 10px;
                }

        .form-input {
                    flex: 1;
                    padding: 8px;
                    border: 1px solid #ccc;
                    border-radius: 3px;
                }

        .form-button {
                    padding: 8px 15px;
                    background-color: #f4f4f4;
                    border: 1px solid #ccc;
                    border-radius: 3px;
                    cursor: pointer;
                }
    </style>
</head>

<body>

<div class="H-padding-vertical-bottom-10"></div>
<header class="H-header H-theme-background-color9 H-padding-vertical-top-25" id="header">
    <span onclick="goBack()" class="H-icon H-position-relative H-display-inline-block H-float-left H-vertical-middle H-theme-font-color-white H-padding-horizontal-left-5 H-z-index-100">
			<i class="H-iconfont H-icon-target-back H-font-size-18 H-vertical-middle"></i>
		</span>
    <div class="H-header-title H-center-all H-font-size-18 H-text-show-row-1 H-theme-font-color-white
            H-position-absolute H-width-100-percent">商家账号添加</div>
</header>

<div class="H-padding-vertical-bottom-10"></div>

<div class="H-border-vertical-both-after">
    <div class="form-item">
        <span class="form-label">商家名：</span>
        <input type="text" class="form-input" id="merchantName" placeholder="请输入商家名" />
    </div>
    <div class="form-item">
        <span class="form-label">手机号：</span>
        <input type="text" class="form-input" id="phoneNumber" placeholder="请输入手机号" />
    </div>
    <div class="form-item">
        <span class="form-label">注册时间：</span>
        <input type="text" class="form-input" id="registerTime" placeholder="请输入注册时间（格式如：2025-01-01 12:00:00）" />
    </div>
    <div class="form-item">
        <button class="form-button" onclick="addMerchantAccount()">添加</button>
    </div>
</div>

<script src="../../script/H.js" type="text/javascript"></script>
<script src="../../script/jquery-3.7.1.min.js" type="text/javascript"></script>
<script src="../api.js" type="text/javascript"></script>
<script type="text/javascript">
    function addMerchantAccount() {
        var merchantName = $('#merchantName').val();
        var phoneNumber = $('#phoneNumber').val();
        var registerTime = $('#registerTime').val();
        if (merchantName == '') {
            alert('请输入商家名');
            return false;
        }
        if (phoneNumber == '') {
            alert('请输入手机号');
            return false;
        }
        if (registerTime == '') {
            alert('请输入注册时间');
            return false;
        }
        // 生成默认密码为手机号后六位
        var defaultPassword = phoneNumber.slice(-6);
        var baseServer = ""; // 实际需根据后端提供地址修改
        $.ajax({
            url: baseServer + 'addMerchantAccountUrl',
            type: 'POST',
            contentType: 'application/json;charset=utf-8',
            dataType: "json",
            data: JSON.stringify({
                merchantName: merchantName,
                phoneNumber: phoneNumber,
                password: defaultPassword,
                registerTime: registerTime
            }),
            success: function (data) {
                if (data.success) {
                    alert('商家账号添加成功');
                } else {
                    alert(data.message);
                }
            },
            error: function (xhr, type) {
                alert('网络错误，请稍后再试');
            }
        });
    }
</script>

</body>

</html>